﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.CMS.MODEL;

namespace Jxym.wlkc2011.WebSite
{
    public partial class Content : System.Web.UI.Page
    {
        #region 字段|属性

        private int _contentId;
        private string _siteName;
        private string _navigationHtml;
        private string _videoFile;
        public string VideoFile
        {
            get { return _videoFile; }
            set { _videoFile = value; }
        }
        private string _menuTitle;
        private string _contentHtml = "没有找到相关信息，已删除或已移动";
        private string _contentTitle = "提示信息";
        private string _contentUser;
        private string _contentDate;
        public string ContentHtml
        {
            get { return _contentHtml; }
            set { _contentHtml = value; }
        }
        public string ContentTitle
        {
            get { return _contentTitle; }
            set { _contentTitle = value; }
        }
        public string ContentUser
        {
            get { return _contentUser; }
            set { _contentUser = value; }
        }
        public string ContentDate
        {
            get { return _contentDate; }
            set { _contentDate = value; }
        }
        public string NavigationHtml
        {
            get { return _navigationHtml; }
            set { _navigationHtml = value; }
        }
        public string MenuTitle
        {
            get { return _menuTitle; }
            set { _menuTitle = value; }
        }
        public string SiteName
        {
            get { return _siteName; }
            set { _siteName = value; }
        }
        public string label1 = "";
        public int _menuId { get; set; }
        MsSqlDal<Cms_ContentClass> ccc = new MsSqlDal<Cms_ContentClass>();
        private string menuStr;

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["siteName"] != null)
            {
                _siteName = Request.Params["siteName"];
            }
            if (Request.Params["menuid"] != null)
            {
                _menuId = Convert.ToInt32(Request.Params["menuid"]);
            }
            if (Request.Params["menu"] != null)
            {
                menuStr = Request.Params["menu"];
                string[] menus = menuStr.Split('_');
                foreach (string menu in menus)
                {
                    Cms_ContentClass cccInfo = ccc.GetModel(menu);
                    _navigationHtml += "&nbsp;&gt;&nbsp;" + cccInfo.Title;
                }
            }

            MsSqlDal<Cms_Content> cct = new MsSqlDal<Cms_Content>();

            if (Request.Params["contentclassid"] != null)
            {
                _contentId = Convert.ToInt32(Request.Params["contentclassid"]);

                if (_contentId == 0) return;

                Cms_ContentClass info = ccc.GetModel(_contentId);

                _menuTitle = info.Title;

                IList<Cms_Content> list = cct.GetList("ContentClassID=" + _contentId, null, "", 0);
                if (info.Title == "相关资源")
                {
                    Repeater1.Visible = false;
                    _ContentPanel.Visible = false;
                    xgzy.Visible = true;
                    bb.Visible = false;
                }
                GetMenuByID(list, _contentId);
            }

            if (Request.Params["siteName"] != null)
            {
                _siteName = Request.Params["siteName"];
                Jxym.wlkc2011.MyGet.GetIDByName(zjgx1, "主讲人");
                GetIDByName(xgzyList, "相关资源");
                GetIDByName(spxx1, "视频学习");
            }

        }

        private void GetMenuByID(IList<Cms_Content> list, int contentId)
        {
            if (Request.Params["siteName"] != null)
            {
                _siteName = Request.Params["siteName"];
            }
            if (list.Count <= 0)
            {
                GetMenuCByID(contentId);
            }
            else if (list.Count == 1)
            {
                _ListPanel.Visible = false;
                _ContentPanel.Visible = true;
                xgzy.Visible = false;
                label1 = "";
                Cms_Content cctInfo = list[0];
                _contentTitle = cctInfo.Title;
                if (_contentTitle == "主讲人" || _contentTitle == "课程描述")
                {
                    bb.Visible = false;
                    Div1.Visible = true;
                    Literal1.Text = "<img src=\"" + "UpFiles/" + _siteName + "/" + list[0].ViewPhoto + "\" width=434; height=279; style=\" float:none;" + "\"/>";
                }

                _videoFile = (cctInfo.VideoFileName != "no.flv" && cctInfo.VideoFileName != "") ? "<a class=\"video\" href=\"" + _siteName + "_newVideo_" + cctInfo.ID + ".htm\" target=\"_blank\" title=\"相关视频\">相关视频</a>" : "";
                _contentUser = cctInfo.AddUser;
                _contentDate = cctInfo.AddTime.ToString("yyyy年MM月dd日");
                _contentHtml = Module.CMS.Public.cmsPublic.ViewContent(_siteName, cctInfo, "660px", "920px");
            }
            else
            {
                Cms_ContentClass info = ccc.GetModel(_contentId);

                if (info.Title == "相关资源")
                {
                    Literal2.Text = "<img src=\"" + "UpFiles/" + _siteName + "/" + list[0].ViewPhoto + "\" style=\" float:none;; padding:5px 5px;  width:434px; height:279px;/>";
                }
                else if (info.Title == "视频学习")
                {
                    spxx.Visible = true;
                    bb.Visible = false;
                    _ListPanel.Visible = false;
                }
                else
                {
                    _ListPanel.Visible = true;
                    _ContentPanel.Visible = false;
                    dimg.Visible = false;
                    label1 = "";
                    Repeater1.DataSource = list;
                    Repeater1.DataBind();
                }
            }
        }

        private void GetMenuCByID(int contentId)
        {
            MsSqlDal<Cms_Content> mcc = new MsSqlDal<Cms_Content>();
            MsSqlDal<Cms_ContentClass> mcsc = new MsSqlDal<Cms_ContentClass>();
            IList<Cms_ContentClass> mcscList = mcsc.GetList("ParentID=" + contentId, null, "", 0);
            if (mcscList.Count > 0)
            {
                _ListPanel.Visible = false;
                _ContentPanel.Visible = true;
                label1 = "";
                Cms_Content cctInfo = mcc.GetModel("ContentClassID=" + mcscList[0].ID, null);
                if (cctInfo != null)
                {
                    _contentTitle = cctInfo.Title;
                    _videoFile = (cctInfo.VideoFileName != "no.flv" && cctInfo.VideoFileName != "") ? "<a class=\"video\" href=\"" + this._siteName + "_newVideo_" + cctInfo.ID + ".htm\" target=\"_blank\" title=\"相关视频\">相关视频</a>" : "";
                    _contentUser = cctInfo.AddUser;
                    _contentDate = cctInfo.AddTime.ToString("yyyy年MM月dd日");
                    _contentHtml = Module.CMS.Public.cmsPublic.ViewContent(_siteName, cctInfo, "700px", "480px");
                }
                else
                {
                    GetMenuCByID(mcscList[0].ID);
                }
            }
            else
            {
                _ListPanel.Visible = false;
                _ContentPanel.Visible = false;
                label1 = "<div class=\"msg\">暂无信息</div>";
            }
        }
        
        public void GetIDByName(xgzy var, string menuName)
        {
            var.Visible = true;
            MsSqlDal<Cms_Site_ContentClass> mcscc = new MsSqlDal<Cms_Site_ContentClass>();
            IList<Cms_Site_ContentClass> list = mcscc.GetList("SiteName='" + _siteName + "'", null, "", 0);
            foreach (Cms_Site_ContentClass info in list)
            {
                MsSqlDal<Cms_ContentClass> mcsc = new MsSqlDal<Cms_ContentClass>();
                Cms_ContentClass info2 = mcsc.GetModel(info.ContentClassID);
                if (info2 != null)
                {
                    if (info2.Title == menuName)
                    {
                        MsSqlDal<Cms_ContentClass> mcsc3 = new MsSqlDal<Cms_ContentClass>();
                        IList<Cms_ContentClass> list3 = mcsc.GetList("ID=" + info2.ID, null, "", 0);
                        foreach (Cms_ContentClass info3 in list3)
                        {
                            if (info3.Title == var.MyTitle)
                            {
                                var.MyHref = "menu" + info2.ID + "_" + info3.ID + ".htm";
                                var.MyContentClassID = info3.ID;
                            }
                        }
                    }
                }
            }
        }
        public void GetIDByName(mylist var, string menuName)
        {
            var.Visible = true;
            MsSqlDal<Cms_Site_ContentClass> mcscc = new MsSqlDal<Cms_Site_ContentClass>();
            IList<Cms_Site_ContentClass> list = mcscc.GetList("SiteName='" + _siteName + "'", null, "", 0);
            foreach (Cms_Site_ContentClass info in list)
            {
                MsSqlDal<Cms_ContentClass> mcsc = new MsSqlDal<Cms_ContentClass>();
                Cms_ContentClass info2 = mcsc.GetModel(info.ContentClassID);
                if (info2 != null)
                {
                    if (info2.Title == menuName)
                    {
                        MsSqlDal<Cms_ContentClass> mcsc3 = new MsSqlDal<Cms_ContentClass>();
                        IList<Cms_ContentClass> list3 = mcsc.GetList("ID=" + info2.ID, null, "", 0);
                        foreach (Cms_ContentClass info3 in list3)
                        {
                            if (info3.Title == var.MyTitle)
                            {
                                var.MyHref = "menu" + info2.ID + "_" + info3.ID + ".htm";
                                var.MyContentClassID = info3.ID;
                            }
                        }
                    }
                }
            }
        }
        public void GetIDByName(spxx var, string menuName)
        {
            var.Visible = true;
            MsSqlDal<Cms_Site_ContentClass> mcscc = new MsSqlDal<Cms_Site_ContentClass>();
            IList<Cms_Site_ContentClass> list = mcscc.GetList("SiteName='" + _siteName + "'", null, "", 0);
            foreach (Cms_Site_ContentClass info in list)
            {
                MsSqlDal<Cms_ContentClass> mcsc = new MsSqlDal<Cms_ContentClass>();
                Cms_ContentClass info2 = mcsc.GetModel(info.ContentClassID);
                if (info2 != null)
                {
                    if (info2.Title == menuName)
                    {
                        MsSqlDal<Cms_ContentClass> mcsc3 = new MsSqlDal<Cms_ContentClass>();
                        IList<Cms_ContentClass> list3 = mcsc.GetList("ID=" + info2.ID, null, "", 0);
                        foreach (Cms_ContentClass info3 in list3)
                        {
                            if (info3.Title == var.MyTitle)
                            {
                                var.MyHref = "menu" + info2.ID + "_" + info3.ID + ".htm";
                                var.MyContentClassID = info3.ID;
                            }
                        }
                    }
                }
            }
        }
        public void GetIDByName(tp var, string menuName)
        {
            var.Visible = true;
            MsSqlDal<Cms_Site_ContentClass> mcscc = new MsSqlDal<Cms_Site_ContentClass>();
            IList<Cms_Site_ContentClass> list = mcscc.GetList("SiteName='" + _siteName + "'", null, "", 0);
            foreach (Cms_Site_ContentClass info in list)
            {
                MsSqlDal<Cms_ContentClass> mcsc = new MsSqlDal<Cms_ContentClass>();
                Cms_ContentClass info2 = mcsc.GetModel(info.ContentClassID);
                if (info2 != null)
                {
                    if (info2.Title == menuName)
                    {
                        MsSqlDal<Cms_ContentClass> mcsc3 = new MsSqlDal<Cms_ContentClass>();
                        IList<Cms_ContentClass> list3 = mcsc.GetList("ID=" + info2.ID, null, "", 0);
                        foreach (Cms_ContentClass info3 in list3)
                        {
                            if (info3.Title == var.MyTitle)
                            {
                                var.MyHref = "menu" + info2.ID + "_" + info3.ID + ".htm";
                                var.MyContentClassID = info3.ID;
                            }
                        }
                    }
                }
            }
        }
    }
}